﻿using System.Diagnostics;
using System;

namespace MaterialTypeRecognition.Shell.Utils
{
    public class StopwatchTimer
    {
        private Stopwatch stopwatch;

        public TimeSpan Elapsed => stopwatch.Elapsed; // 经过的时间

        public bool IsRunning => stopwatch.IsRunning; // 计时器是否正在运行

        public bool IsTimeUp => Elapsed >= TargetTime; // 是否时间到

        public TimeSpan TargetTime { get; private set; } // 目标时间

        public StopwatchTimer()
        {
            stopwatch = new Stopwatch();
        }

        public void Start(TimeSpan targetTime)
        {
            TargetTime = targetTime;
            stopwatch.Reset();
            stopwatch.Start();
        }

        public void Stop()
        {
            stopwatch.Stop();
        }

        public void Reset()
        {
            stopwatch.Reset();
        }
    }
}
